<?php
	# Sites definition
	require('includes/sites/config.php');
	include("includes/classes/node.php");
	include("includes/classes/sites.php");
	include("includes/classes/standard.php");
	include("includes/classes/category.php");
	include("includes/classes/address.php");
	include("includes/classes/item.php");
	include("includes/classes/cart.php");
	include("includes/classes/order.php");
	include("includes/classes/user.php");
	include("includes/classes/location.php");

	
	$server= new server();
	#We load the sites to the server
	$server->load_sites();
	$_GET["domain"]="www.cosmetica.com";
	$server->set_default($_GET["domain"]);
	
	$server->init();
	
	print_r($server);
	$my_catalog=new category();
	$my_catalog->db_load_subcategories();
	foreach ($my_catalog->categories as $category) {
		$category->db_load_subcategories();
		foreach ($category->categories as $subcategory) {
			$subcategory->db_load_items();
		}
	}
	print htmlentities(json_encode($my_catalog));
	$myuser=new user();
	$myuser->email="melchorherrera@gmail.com";
	$myuser->password="try";
	if ($myuser->login()) {
		$myuser->db_load();
		$myuser->address=new address();
		$myuser->address->id=$myuser->address_id;
		$myuser->address->db_load();
		$myuser->order=new order();
		$myuser->order->user_id=$myuser->id;
		$myuser->order->status=9;
		$myuser->order->db_get_last(">0");
		$myuser->order->db_load();
		$myuser->order->db_load_items();
		$cartPrice=0;
		foreach ($myuser->order->items as $item) {
			$cartPrice+=$item->price * $item->quantity;
		}
		$myuser->order->subTotal=$cartPrice;
		$myuser->order->payment=new payment();
		$myuser->order->payment->db_load_methods();
		$myuser->order->payment->method=new payment_method();
		$myuser->order->payment->method->id=$myuser->order->payment_method_id;
		$myuser->order->payment->method->db_load();
		$myuser->order->delivery=new delivery();
		if ($myuser->order->phone) $myuser->order->delivery->phone=$myuser->order->phone; 
		else $myuser->order->delivery->phone=$myuser->phone;
		$myuser->order->delivery->db_load_shipping_types();
		$myuser->order->delivery->shipping_type=new shipping_type();
		$myuser->order->delivery->shipping_type->id=$myuser->order->shipping_type_id;
		$myuser->order->delivery->shipping_type->db_load();
		$myuser->order->delivery->address=new address();
		if ($myuser->order->address_id) { 
			$myuser->order->delivery->address->id=$myuser->order->address_id;
		}
		else {
			$myuser->order->delivery->address->id=$myuser->address_id;
		}
		$myuser->order->delivery->address->db_load();
		$myuser->order->delivery->address->country=new country();
		$myuser->order->delivery->address->country->id=$myuser->order->delivery->address->country_id;
		$myuser->order->delivery->address->country->db_load();
		$myuser->order->delivery->address->zone=new zone();
		$myuser->order->delivery->address->zone->id=$myuser->order->delivery->address->zone_id;
		$myuser->order->delivery->address->zone->db_load();
	}
	elseif ($myuser->id) {
		echo "password incorrect";
	}
	else {
		echo "user doen't exist";
	}
	print_r($myuser);

?>

